home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / modex32w.zip / WRPIX.ASM < prev   
Assembly Source File  |  1995-02-21  |  2KB  |  64 lines

  1.         .386p
  2.         locals
  3.         include w.inc
  4.  
  5. ; Mode X (320x240, 256 colors) write pixel routine. Works on all VGAs.
  6. ; No clipping is performed.
  7. ; C near-callable as:
  8. ;    void WritePixelX(int X, int Y, unsigned int PageBase, int Color);
  9. ;
  10. ; Modified Aug 30, 1994 (ykumanan)
  11. ; ) Made code 32 bit pm (not fully optimized)
  12. ;
  13.  
  14. SC_INDEX equ    03c4h   ;Sequence Controller Index
  15. MAP_MASK equ    02h     ;index in SC of Map Mask register
  16.  
  17. parms   struc
  18.         dd      2 dup (?) ;pushed EBP and return address
  19. X       dd      ?       ;X coordinate of pixel to draw
  20. Y       dd      ?       ;Y coordinate of pixel to draw
  21. PageBase dd     ?       ;base offset in display memory of page in
  22.                         ; which to draw pixel
  23. Color   dd      ?       ;color in which to draw pixel
  24. parms   ends
  25.  
  26.         @dseg
  27.  
  28.         extrn   SCREEN_SEG:dword
  29.         extrn   SCREEN_WIDTH:dword       ;width of screen in bytes from
  30.                                          ; one scan line to the next
  31.  
  32.         ends
  33.  
  34.         @cseg
  35.         public  _WritePixelX
  36. _WritePixelX    proc    near
  37.         push    ebp      ;preserve caller's stack frame
  38.         mov     ebp,esp   ;point to local stack frame
  39.  
  40.         mov     eax,[SCREEN_WIDTH]
  41.         mul     [ebp+Y]  ;offset of pixel's scan line in page
  42.         mov     ebx,[ebp+X]
  43.         shr     ebx,2    ;X/4 = offset of pixel in scan line
  44.         add     ebx,eax   ;offset of pixel in page
  45.         add     ebx,[ebp+PageBase] ;offset of pixel in display memory
  46.         add     ebx, [SCREEN_SEG]
  47.  
  48.         mov     cl,byte ptr [ebp+X]
  49.         and     cl,011b ;CL = pixel's plane
  50.         mov     ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
  51.         shl     ah,cl   ;set only the bit for the pixel's plane to 1
  52.         mov     dx,SC_INDEX ;set the Map Mask to enable only the
  53.         out     dx,ax       ; pixel's plane
  54.  
  55.         mov     al,byte ptr [ebp+Color]
  56.         mov     [ebx],al ;draw the pixel in the desired color
  57.  
  58.         pop     ebp      ;restore caller's stack frame
  59.         ret
  60. _WritePixelX    endp
  61.         ends
  62.         end
  63.  
  64.